From 707f3f6f21b74e47e23fc6409a22018bcffe3ed0 Mon Sep 17 00:00:00 2001 From: tsteven4 Date: Fri, 8 Dec 2017 08:20:30 -0700 Subject: [PATCH] gui map js beautification and corrections. --- gui/map.cc | 56 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/gui/map.cc b/gui/map.cc index 9bed4a32f..a4fe2a262 100644 --- a/gui/map.cc +++ b/gui/map.cc @@ -143,6 +143,28 @@ static QString fmtLatLng(const LatLng &l) { return QString("{lat: %1, lng: %3}").arg(l.lat(), 0, 'f', 5) .arg(l.lng(), 0, 'f', 5); } +//------------------------------------------------------------------------ +static QString makePath(const vector &pts) { + // maps v3 Polylines do not use encoded paths. + QString path; + int lncount = 0; + bool someoutput = false; + foreach (const LatLng ll, pts) { + if (lncount == 0) { + if (someoutput) { + path.append(QChar(',')); + } + path.append(QLatin1String("\n ")); + } else if (lncount == 1) { + path.append(QLatin1String(", ")); + } + path.append(fmtLatLng(ll)); + someoutput = true; + lncount = (lncount + 1) % 2; + } + return path; +} + //------------------------------------------------------------------------ void Map::showGpxData() { @@ -200,17 +222,12 @@ void Map::showGpxData() pts.push_back(pt.getLocation()); } } - // maps v3 Polylines do not use encoded paths. - foreach (const LatLng ll, pts) { - path.append(fmtLatLng(ll)); - path.append(QLatin1String(", ")); - } - path.chop(2); + path = makePath(pts); scriptStr << QString("trks[%1] = new RTPolyline(\n" " map,\n" - " new google.maps.Polyline({map: map, strokeColor: \"#0000E0\", strokeWeight: 2, strokeOpacity: 0.6, path: [%2]}),\n" + " new google.maps.Polyline({\n map: map,\n strokeColor: \"#0000E0\",\n strokeWeight: 2,\n strokeOpacity: 0.6,\n path: [%2\n ]\n }),\n" " new google.maps.LatLng(%3),\n" " new google.maps.LatLng(%4),\n" " \"%5\",\n" @@ -233,17 +250,12 @@ void Map::showGpxData() foreach (const GpxRoutePoint &pt, rte.getRoutePoints()) { pts.push_back(pt.getLocation()); } - // maps v3 Polylines do not use encoded paths. - foreach (const LatLng ll, pts) { - path.append(fmtLatLng(ll)); - path.append(QLatin1String(", ")); - } - path.chop(2); + path = makePath(pts); scriptStr << QString("rtes[%1] = new RTPolyline(\n" " map,\n" - " new google.maps.Polyline({map: map, strokeColor: \"#0000E0\", strokeWeight: 2, strokeOpacity: 0.6, path: [%2]}),\n" + " new google.maps.Polyline({\n map: map,\n strokeColor: \"#8000B0\",\n strokeWeight: 2,\n strokeOpacity: 0.6,\n path: [%2\n ]\n }),\n" " new google.maps.LatLng(%3),\n" " new google.maps.LatLng(%4),\n" " \"%5\",\n" @@ -306,8 +318,8 @@ void Map::hideAllTracks() { QStringList scriptStr; scriptStr - << "for( var i=0; i